/**
 * entrance of Lite
 */
function Lite() {
    // initial params here
}
Lite.prototype = {
    use: function (module_name_list, callback) {
        for (var module_index in module_name_list) {
            var moduleLst = this.getCmp(module_name_list[module_index]);
            var childDom;
            for (var i in moduleLst) {
                var strPartArr = moduleLst[i].split(".");
                if ("js" == strPartArr[strPartArr.length - 1]) {
                    childDom = this.addScript("head", module_name_list[module_index] + "/" + moduleLst[i]);
                } else if ("css" == strPartArr[strPartArr.length - 1]) {
                    childDom = this.addCSS("head", module_name_list[module_index] + "/" + moduleLst[i]);
                }
            }
            if (module_index == module_name_list.length - 1) {
                if ("text/css" == childDom.type) {
                    styleOnload(childDom, function () {
                        if (callback) {
                            callback();
                        }
                    });
                } else if ("text/javascript" == childDom.type) {
                    childDom.onload = function () {
                        if (callback) {
                            callback();
                        }
                    };
                }
            }
        }
    },
    addScript: function (parent, path) {
        var pDom = document.getElementsByTagName(parent)[0];
        var cDom = document.createElement("script");
        cDom.type = "text/javascript";
        cDom.src = path;
        pDom.appendChild(cDom);
        return cDom;
    },
    addCSS: function (parent, path) {
        var pDom = document.getElementsByTagName(parent)[0];
        var cDom = document.createElement("link");
        cDom.type = "text/css";
        cDom.rel = "stylesheet";
        cDom.href = path;
        pDom.appendChild(cDom);
        return cDom;
    },
    getCmp: function (param) {
        if (ElCompent.hasOwnProperty(param)) {
            return ElCompent[param];
        }
    },
};

var elite = new Lite();
/**
 * define the packages structure
 */
var ElCompent = {
    "UI": ["UI.css"],
    "core": ["Observer.js", "Watcher.js", "Compile.js", "EDAO.js", "ECtrl.js"],
    "move": ["mover.js"],
    "spagination": ["spagination.css", "spagination.js"],
    "http": ["http.js"]
};
/**
 * sea.js
 */
function styleOnload(node, callback) {
    // for IE6-9 and Opera
    if (node.attachEvent) {
        node.attachEvent('onload', callback);
        // NOTICE:
        // 1. "onload" will be fired in IE6-9 when the file is 404, but in
        // this situation, Opera does nothing, so fallback to timeout.
        // 2. "onerror" doesn't fire in any browsers!
    }
    // polling for Firefox, Chrome, Safari
    else {
        setTimeout(function () {
            poll(node, callback);
        }, 0); // for cache
    }
}
function poll(node, callback) {
    if (callback.isCalled) {
        return;
    }
    var isLoaded = false;
    if (/webkit/i.test(navigator.userAgent)) {//webkit
        if (node['sheet']) {
            isLoaded = true;
        }
    }
    // for Firefox
    else if (node['sheet']) {
        try {
            if (node['sheet'].cssRules) {
                isLoaded = true;
            }
        } catch (ex) {
            // NS_ERROR_DOM_SECURITY_ERR
            if (ex.code === 1000) {
                isLoaded = true;
            }
        }
    }
    if (isLoaded) {
        // give time to render.
        setTimeout(function () {
            callback();
        }, 1);
    }
    else {
        setTimeout(function () {
            poll(node, callback);
        }, 1);
    }
}